package ajax.quanxuan.sys.service.impl;

import ajax.quanxuan.sys.entity.Dept;
import ajax.quanxuan.sys.dao.DeptMapper;
import ajax.quanxuan.sys.service.DeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author KazuGin
 * @since 2024-07-07
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
    @Autowired
    private DeptMapper deptMapper;


    @Override
    public Object list(Dept dept) {
      /*  PageHelper.startPage(1, 10);
        PageInfo<Dept> deptPageInfo = new PageInfo<>(deptMapper.list(dept));
        deptPageInfo.getTotal();*/
        if (dept.getPage()<0){
            dept.setPage(1);
        }
        //获取最大数量
        Integer count =Integer.valueOf(deptMapper.count(dept));
        //获取总页数   count/rows
        Integer size = count / dept.getLimit();
        if (count % dept.getLimit() > 0) {
            size++;
        }
        dept.setSize(size);
        //如果当前页数大于总页数   则当前页等于总页数
        if (size == 0) {
            dept.setPage(1);
        } else if (dept.getPage() > dept.getSize()) {
            dept.setPage(size);
        }
        dept.setCurrIndex((dept.getPage() - 1) * dept.getLimit());
        dept.setPageSize(dept.getLimit());

        return deptMapper.list(dept);
    }

    @Override
    public List<Dept> list1(Dept dept) {
        return deptMapper.list1(dept);
    }

    @Override
    public Integer count(Dept dept) {
        return deptMapper.count(dept);
    }


}
